<#include "/admin/_inc/_head.html"/>
<#include "/admin/_inc/_layout.html" />
<!DOCTYPE html>
<html lang="en">

<head>
    <@head />
    <link href="/assets/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/assets/css/plugins/zTree/v3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <style type="text/css">

        .mfs-selected-option {
            border: 1px #ccc solid;
            display: inline-block;
            width: 100%;
            font-size: 14px;
            height: 31px;
            line-height: 2.42857;
            padding-left: 4px;
        }

        .mfs-options {
            position: absolute;
            border: 1px #ccc solid;
            /* border-top:0px; */
            width: 100%;
            margin: 0;
            padding: 0px;
            color: #333;
            overflow: auto;
            min-height: 100px;
            max-height: 300px;
            background: #ffffff;
            z-index: 9;
            margin-top: -6px;
        }
    </style>
</head>

<body>
<@layout>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">

            <div class="ibox-content">
                <form action="<#if model?exists>${ctx_admin}/wx-button/update<#else>${ctx_admin}/wx-button/add</#if>" method="post" class="form form-horizontal"
                      id="form">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">
                            上级菜单
                        </label>
                        <div class="col-sm-8">
                            <input type="hidden" name="id" value="${model.id}">
                            <input type="text"  class="form-control" id="pId" name="pId" placeholder="" readonly="readonly"  required=""
                                   aria-required="true"  value="${model.pId}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">
                            菜单名称
                        </label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" placeholder="" name="name" required=""
                                   aria-required="true" value="${model.name}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">
                            菜单标识：</label>
                        <div class="col-sm-8">
                            <input type="text" placeholder=""  class="form-control" required=""
                                   aria-required="true" name="buttonKey" value="${model.buttonKey}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">菜单类型：</label>
                        <div class="col-sm-8">
                            <input id="h_sex" type="hidden" value="${model.stype}">
                            <select class="form-control" id="type" name="type" size="1" required=""
                                    aria-required="true" >
                                <!-- <option value="click">消息触发类</option> -->
                                <option value="view">网页链接类</option>
                                <!-- <option value="scancode_push">扫码推事件</option>
                                <option value="scancode_waitmsg">扫码带提示</option>
                                <option value="pic_sysphoto">系统拍照发图</option>
                                <option value="pic_photo_or_album">拍照或者相册发图</option>
                                <option value="pic_weixin">微信相册发图</option>
                                <option value="location_select">发送位置</option>
                                <option value="media_id">图片</option>
                                <option value="view_limited">图文消息</option> -->
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">URL</label>
                        <div class="col-sm-8">
                            <input type="text" placeholder="" class="form-control" name="url" required=""
                                   aria-required="true" value="${model.url}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">排序</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" placeholder="" name="orders" required=""
                                   aria-required="true"  value="${model.orders}" >
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-3 text-center">
                            <button id="btn-submit" class="btn btn-primary" type="submit">提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

    </div>

</div>



</@layout>

<script src="/assets/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/assets/js/plugins/validate/messages_zh.min.js"></script>
<script src="/assets/js/plugins/jquery.form/jquery.form.js"></script>
<script type="text/javascript" src="/assets/js/plugins/zTree/v3/js/jquery.ztree.all-3.5.js"></script>
<script type="text/javascript" src="/assets/js/droptree.js"></script>
<script type="text/javascript">
    $(function () {
        wxbuttonTree.getPerentButton();

        $("#form").validate({
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    type: 'post',
                    url: form.action,
                    success: function (data) {
                        if (data.success) {
                            layer.msg(data.message, { icon: 1, time: 2000 }, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.$table.bootstrapTable('destroy');
                                parent.initTable();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(data.message, { icon: 2, time: 3000 }, function () { });
                        }
                    },
                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                        layer.msg('error!', { icon: 2, time: 3000 }, function () { });
                    }
                });
            }
        });

    });

    var wxbuttonTree={
        getPerentButton:function(){
            $.ajax({
                type: "POST",
                data: {},
                dataType: 'json',
                url: global.adminPath+'/wx-button/tree',
                success: function(res){
                    //$.fn.zTree.init($("#resourceTree"), resourceTree.setting, res.data);
                    $("#pId").droptree({
                        items:res.data ,
                        transition:"ztree",
                        idLabel:"id",
                        textLabel:"name",
                        pidLabel:"pId",
                        rootPId:0
                    });
                }
            });
        }

    }
</script>


</body>

</html>